package com.gym.redis;

import lombok.Data;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;

/**
 * @author
 */
@Data
@Service
public class RedisPoolFactory {
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.database}")
    private Integer database;

    /**
     * 将redis连接池注入spring容器
     *
     * @return
     */
    @Bean
    public JedisPool jedisPoolFactory() {
        return new JedisPool(new GenericObjectPoolConfig(), host, port, timeout * 1000, password, database);
    }
}
